// 导入路由配置项
import Vue from 'vue'
import VueRouter from 'vue-router'
// 导入组件
import Index from '@/components/LayoutIndex.vue'
// 工作台
import Home from '@/views/Home'
// 预约管理
import Subscribe from '@/views/Subscribe'
// 费用管理
import Cost from '@/views/Cost'
// 医院信息
import Hospital from '@/views/Hospital'
// 系统设置
import SysSetting from '@/views/SysSetting'


// 挂载路由
Vue.use(VueRouter)

const routes = [{
    path: '/',
    component: Index,
    redirect: '/home',
    children: [{
        path: 'home',
        name: 'Home',
        component: Home,
        redirect: '/home/work',
        children: [{
            path: 'work',
            name: 'Work',
            component: () =>
                import ( /* webpackChunkName: "Work" */ '@/views/Home/HomeView.vue'),
        }]
    }, {
        // 预约管理
        path: 'subscribe',
        name: 'Subscribe',
        component: Subscribe,
        redirect: '/subscribe/reg',
        children: [{
                path: 'reg',
                name: 'Reg',
                component: () =>
                    import ( /* webpackChunkName: "Reg" */ '@/views/Subscribe/RegView.vue'),
            },
            {
                path: 'nucleic',
                name: 'Nucleic',
                component: () =>
                    import ( /* webpackChunkName: "Nucleic" */ '@/views/Subscribe/NucleicView.vue'),
            },
            {
                path: 'physical',
                name: 'Physical',
                component: () =>
                    import ( /* webpackChunkName: "Work" */ '@/views/Subscribe/PhysicalView.vue'),
            },
            {
                path: 'scheduling',
                name: 'Scheduling',
                component: () =>
                    import ( /* webpackChunkName: "Work" */ '@/views/Subscribe/SchedulingView.vue'),
            },
            {
                path: 'detail',
                name: 'Detail',
                component: () =>
                    import ( /* webpackChunkName: "Work" */ '@/views/Subscribe/detail.vue'),
            },
            {
                path: 'checkdetail',
                name: 'Checkdetail',
                component: () =>
                    import ( /* webpackChunkName: "Work" */ '@/views/Subscribe/checkdetail.vue'),
            },
            {
                path: 'tjmessage',
                name: 'Tjmessage',
                component: () =>
                    import ( /* webpackChunkName: "Work" */ '@/views/Subscribe/tjmessage.vue'),
            }
        ]
    }, {
        // 费用管理
        path: 'cost',
        name: 'Cost',
        component: Cost,
        redirect: '/cost/outpatientconsume',
        children: [{
                path: 'outpatientconsume',
                name: 'OutpatientConsume',
                component: () =>
                    import ( /* webpackChunkName: "OutpatientConsume" */ '@/views/Cost/OutpatientConsumeView.vue'),
            },
            {
                path: 'outpatientpay',
                name: 'OutpatientPay',
                component: () =>
                    import ( /* webpackChunkName: "OutpatientPay" */ '@/views/Cost/OutpatientPayView.vue'),
            },
            {
                path: 'hospitalconsume',
                name: 'HospitalConsume',
                component: () =>
                    import ( /* webpackChunkName: "HospitalConsume" */ '@/views/Cost/HospitalConsumeView.vue'),
            },
            {
                path: 'hospitalpay',
                name: 'HospitalPay',
                component: () =>
                    import ( /* webpackChunkName: "HospitalPay" */ '@/views/Cost/HospitalPayView.vue'),
            },
            {
                path: 'refund',
                name: 'Refund',
                component: () =>
                    import ( /* webpackChunkName: "Refund" */ '@/views/Cost/RefundView.vue'),
            },
            {
                path: 'detail',
                name: 'detail',
                component: () =>
                    import ( /* webpackChunkName: "Refund" */ '@/views/Cost/detail.vue'),
            },
            {
                path: 'recharge',
                name: 'recharge',
                component: () =>
                    import ( /* webpackChunkName: "Refund" */ '@/views/Cost/recharge.vue'),
            },
            {
                path: 'Consumrecords',
                name: 'Consumrecords',
                component: () =>
                    import ( /* webpackChunkName: "Refund" */ '@/views/Cost/Consumrecords.vue'),
            },
            {
                path: 'Rechargerecord',
                name: 'Rechargerecord',
                component: () =>
                    import ( /* webpackChunkName: "Refund" */ '@/views/Cost/Rechargerecord.vue'),
            },
            {
                path: 'Refundindetail',
                name: 'Refundindetail',
                component: () =>
                    import ( /* webpackChunkName: "Refund" */ '@/views/Cost/Refundindetail.vue'),
            }
        ]
    }, {
        // 医院信息
        path: 'hospital',
        name: 'Hospital',
        component: Hospital,
        redirect: '/Hospital/doctor',
        children: [{
                path: 'doctor',
                name: 'Doctor',
                component: () =>
                    import ( /* webpackChunkName: "Doctor" */ '@/views/Hospital/DoctorView.vue'),
            }, {
                path: 'doctor/add',
                name: 'AddDoctor',
                component: () =>
                    import ( /* webpackChunkName: "AddDoctor" */ '@/views/Hospital/AddDoctorView.vue'),
            },
            {
                path: 'room',
                name: 'Room',
                component: () =>
                    import ( /* webpackChunkName: "Room" */ '@/views/Hospital/RoomView.vue'),
            }, {
                path: 'room/add',
                name: 'AddRoom',
                component: () =>
                    import ( /* webpackChunkName: "AddRoom" */ '@/views/Hospital/AddRoomView.vue'),
            },
            {
                path: 'feel',
                name: 'Feel',
                component: () =>
                    import ( /* webpackChunkName: "Feel" */ '@/views/Hospital/FeelView.vue'),
            }, {
                path: 'feel/add',
                name: 'AddFeel',
                component: () =>
                    import ( /* webpackChunkName: "AddFeel" */ '@/views/Hospital/AddFeelView.vue'),
            },
            {
                path: 'health',
                name: 'Health',
                component: () =>
                    import ( /* webpackChunkName: "Health" */ '@/views/Hospital/HealthView.vue'),
            }, {
                path: 'health/add',
                name: 'AddHealth',
                component: () =>
                    import ( /* webpackChunkName: "AddHealth" */ '@/views/Hospital/AddHealthView.vue'),
            },
            {
                path: 'navigation',
                name: 'Navigation',
                component: () =>
                    import ( /* webpackChunkName: "Navigation" */ '@/views/Hospital/NavigationView.vue'),
            }, {
                path: 'navigation/add',
                name: 'AddNavigation',
                component: () =>
                    import ( /* webpackChunkName: "AddNavigation" */ '@/views/Hospital/AddNavigationView.vue'),
            },
            {
                path: 'brief',
                name: 'Brief',
                component: () =>
                    import ( /* webpackChunkName: "Brief" */ '@/views/Hospital/BriefView.vue'),
            },
            {
                path: 'notice',
                name: 'Notice',
                component: () =>
                    import ( /* webpackChunkName: "Notice" */ '@/views/Hospital/NoticeView.vue'),
            }
        ]
    }, {
        // 系统设置
        path: 'syssetting',
        name: 'SysSetting',
        component: SysSetting,
        redirect: '/syssetting/admin',
        children: [{
                path: 'admin',
                name: 'Admin',
                component: () =>
                    import ( /* webpackChunkName: "Admin" */ '@/views/SysSetting/AdminView.vue'),
            },
            {
                path: 'adminset',
                name: 'AdminSet',
                component: () =>
                    import ( /* webpackChunkName: "Admin" */ '@/views/SysSetting/AdminSet.vue'),
            },
            {
                path: 'role',
                name: 'Role',
                component: () =>
                    import ( /* webpackChunkName: "Role" */ '@/views/SysSetting/RoleView.vue'),
            },
            {
                path: 'roleset',
                name: 'RoleSet',
                component: () =>
                    import ( /* webpackChunkName: "Admin" */ '@/views/SysSetting/RoleSet.vue'),
            },
            {
                path: 'profess',
                name: 'Profess',
                component: () =>
                    import ( /* webpackChunkName: "Profess" */ '@/views/SysSetting/ProfessView.vue'),
            },
            {
                path: 'processset',
                name: 'ProcessSet',
                component: () =>
                    import ( /* webpackChunkName: "Admin" */ '@/views/SysSetting/ProcessSet.vue'),
            },
            {
                path: 'info',
                name: 'Info',
                component: () =>
                    import ( /* webpackChunkName: "Info" */ '@/views/SysSetting/InfoView.vue'),
            },
            {
                path: 'infoset',
                name: 'InfoSet',
                component: () =>
                    import ( /* webpackChunkName: "Admin" */ '@/views/SysSetting/InfoSet.vue'),
            },
            {
                path: 'mod',
                name: 'Mod',
                component: () =>
                    import ( /* webpackChunkName: "Mod" */ '@/views/SysSetting/ModView.vue'),
            }
        ]
    }]
}, {
    path: '/login',
    name: 'Login',
    component: () =>
        import ( /* webpackChunkName: "Login" */ '@/views/Login')
}, {
    path: '*',
    component: () =>
        import ( /* webpackChunkName: "Error" */ '@/views/Error')
}]
const router = new VueRouter({
    // 路由模式
    mode: 'history',
    // 默认地址-相对路径
    base: process.env.BASE_URL,
    // 导入路由
    routes
})

// 增加全局路由守卫
router.beforeEach((to, from, next) => {
        // 获取当前本地登录状态
        const loginState = localStorage.getItem('loginState')
        if (to.path !== '/login') {
            if (loginState) {
                next()
            } else {
                next('/login')
            }
        } else {
            if (loginState) {
                next(from.path)
            } else {
                next()
            }
        }
    })
    // 暴露路由 
export default router